/*
 *  $Id: DefenceAura.cs 1165 2010-10-02 14:32:23Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System.Collections.Generic;

namespace Ragima {
    /// <summary>
    /// Абстрактная аура, действующая на дружественных существ и только в фазу защиты.
    /// </summary>
    public abstract class DefenceAuraAffect: CreatureAuraAffect {
        private bool _defence;

        public DefenceAuraAffect(): base(true, false) {
            _defence = false;
        }

        public override int AverageWeightPercent {
            get { return 250; }
        }

        public override void SetAffect() {
            base.SetAffect();
            GlobalSummary.OnStartDefencePhase += DoSetDefence;
            GlobalSummary.OnEndDefencePhase += DoResetDefence;
        }
        public override void ResetAffect() {
            base.ResetAffect();
            GlobalSummary.OnStartDefencePhase -= DoSetDefence;
            GlobalSummary.OnEndDefencePhase -= DoResetDefence;
        }

        private void DoSetDefence() {
            _defence = true;
            UpdateAura(false);
        }
        private void DoResetDefence() {
            _defence = false;
            UpdateAura(false);
        }

        protected override bool AcceptAura(AbstractObject obj) {
            return _defence && obj is Creature && AcceptOwner(obj);
        }
    }
}